home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvg103_s.zip / TVGRAPH.IN1 < prev    next >
Text File  |  1992-07-29  |  30KB  |  986 lines

  1. (*****************************************************************************)
  2. (*                                                                           *)
  3. (*  TVGRAPH Version 1.0 (C) C.L.Burke. Portions (C) Borland                  *)
  4. (*                                                                           *)
  5. (*  Display Specific routines                                                *)
  6. (*                                                                           *)
  7. (*  0. Do_Set_XXXXXX    - sets all of the functions into the procedure array *)
  8. (*                                                                           *)
  9. (*  1. Do_INIT_XXXXXX   - should initialise all the specific hardware        *)
  10. (*  2. Do_DONE_XXXXXX   - should reset all specific hardware                 *)
  11. (*  3. Do_PixelAddr_XXXXXX                                                   *)
  12. (*                      - in ax=y, bx=x | out AH=unshifted bit mask          *)
  13. (*                      - CL=bits to shift BX = byte offset                  *)
  14. (*  4. TVGraphCursorOn_XXXXXX                                                *)
  15. (*                        These 3 routines assume GLOBAL TvGraphCursor       *)
  16. (*                        has Start in H and end in L. GLOBAL TvGraphLoc     *)
  17. (*                        X in L and Y in H                                  *)
  18. (*                      - Turn Cursor on check TvViziFlag                    *)
  19. (*  5. TVGraphCursorOff_XXXXXX                                               *)
  20. (*                      - Turn Cursor off check TvViziFlag                   *)
  21. (*  6. TVUpdateCursor_XXXXXX                                                 *)
  22. (*                      - Update cursor to current specifications            *)
  23. (*  7. Do_GraphMOV_XXXXX- expect same parameters at REP MOVSW to text video  *)
  24. (*                      - CX = Number of words (HI=Attr,LO=Char) to move     *)
  25. (*                      - DS:SI = Source of words                            *)
  26. (*                      - ES:DI = Normal TEXT destination                    *)
  27. (*  8. NewJmp_GraphMOV_XXXXXX                                                *)
  28. (*                      - Replaces the CheckSnow code in Views unit          *)
  29. (*                      - important that the following structure is kept     *)
  30. (*                                                                           *)
  31. (*                        asm                                                *)
  32. (*                         call far ptr Do_GraphMOV_XXXXXX                   *)
  33. (*                         mov si,es                                         *)
  34. (*                         pop ax                                            *)
  35. (*                         pop cx                                            *)
  36. (*                         pop di                                            *)
  37. (*                         pop ds                                            *)
  38. (*                         pop es                                            *)
  39. (*                         db 0C3H   ( RET NEAR - can't use RET FAR!!!  )    *)
  40. (*                        end;                                               *)
  41. (*  9. procedure Draw_Any_Line_XXXXXX(X1,Y1,X2,Y2,Color:word); assembler;    *)
  42. (*          Generic draw routine assumes X1<X2                               *)
  43. (*                                                                           *)
  44. (* 10. procedure Draw_Horiz_Line_XXXXXX(X1,X2,Y,Color:word); assembler;      *)
  45. (*          Horizontal draw routine assumes X1<X2                            *)
  46. (*                                                                           *)
  47. (* 11. procedure Draw_Vert_Line_XXXXXX(X,Y1,Y2,Color:word); assembler;       *)
  48. (*          Vertical draw routine assumes Y1<Y2                              *)
  49. (*                                                                           *)
  50. (*****************************************************************************)
  51. const  (* EGA Specific constants *)
  52.   EGAVideoMemory     =$A000;
  53.   EGASequencer       =$03C4;
  54.   EGAGraphController =$03CE;
  55.   Set_EnableSR       =$0001;
  56.    UseSR             =$0F00;
  57.    UseCPUMask        =$0000;
  58.   Default_EnableSR   =Set_EnableSR+UseSR;
  59.   Set_RWFunction     =$0003;
  60.    OverWrite         =$0000;
  61.    LogicalAND        =$0800;
  62.    LogicalOR         =$1000;
  63.    LogicalXOR        =$1800;
  64.   Default_RWFunction =Set_RWFunction+OverWrite;
  65.   Set_WriteMode      =$0005;
  66.    Read_Mode_0       =$0000;
  67.    Read_Mode_1       =$0800;
  68.    Write_Mode_0      =$0000;
  69.    Write_Mode_1      =$0100;
  70.    Write_Mode_2      =$0200;
  71.    Write_Mode_3      =$0300;
  72.   Default_WriteMode  =Set_WriteMode+Read_Mode_1+Write_Mode_0;
  73.   Default_ColorPlane =$0007;
  74.   Default_Mask       =$FF08;
  75.  
  76.   BytesInLoop        =10;   (* Bytes in the simulated loop *)
  77.   NumberOfLoops      =16;   (* Number of coded loops *)
  78. var  (* GLobal to free BP in draw line routines *)
  79.  VARSlope:byte; (* 0 = slope < 1 , 1= slope >1 *)
  80.  BitShift,ReInitBit,NegBitShift,
  81.  CharMapPtr,VARVertIncr,VARIncr1,VARIncr2:word;
  82.  
  83.  
  84. Procedure Do_INIT_EGAVGA; assembler;
  85. asm
  86. (* Call once at start of program *)
  87. (* all ega/vga routines should return to this state *)
  88.     push ax
  89.     push cx
  90.     push dx
  91.     push es
  92.     push si
  93.  
  94.     xor ah,ah
  95.     xor ch,ch
  96.     mov ax,[GraphWidth]
  97.     div [CharWidth]
  98.     mul [GraphHeight]
  99.     mov [ColorList],ax
  100.     mov si,ax
  101.     mov ax,[VideoBufferSeg]
  102.     mov es,ax
  103.  
  104.     mov dx,EGAGraphController (* Set up Graphics controller *)
  105.     mov ax,Default_EnableSR
  106.     out dx,ax
  107.     mov ax,Set_WriteMode+Read_Mode_1+Write_Mode_2 (* For Color init next *)
  108.     out dx,ax
  109.     mov ax,Default_RWFunction
  110.     out dx,ax
  111.     mov ax,Default_Mask
  112.     out dx,ax
  113.     mov ax,Default_ColorPlane
  114.     out dx,ax
  115.  
  116.  
  117.     mov al,0ffh
  118.     mov ch,010h
  119.     mov cl,0
  120.     (*  ES:SI = SCreen , CX=Count, DX=port *)
  121. @L10:
  122.     and es:[si],cl
  123.     inc si
  124.     inc cl
  125.     dec ch
  126.     jnz @L10
  127.  
  128.     mov ax,Default_WriteMode
  129.     out dx,ax
  130.  
  131.     (* Set up 16 colors at EGAScreenSegment:[SI] where SI=max-x max-y *)
  132.     pop si
  133.     pop es
  134.     pop dx
  135.     pop cx
  136.     pop ax
  137.     ret
  138. end;
  139.  
  140.  
  141. Procedure Do_DONE_EGAVGA; assembler;
  142. asm
  143. (* Call once at end of program *)
  144.     push ax
  145.     push dx
  146.     mov dx,EGAGraphController  (* Set up Graphics controller *)
  147.     mov ax,Default_Mask  (* Restore CRT registers *)
  148.     out dx,ax
  149.     mov ax,Set_WriteMode+Read_Mode_0+Write_Mode_0
  150.     out dx,ax
  151.     mov ax,Set_RWFunction+OverWrite
  152.     out dx,ax
  153.     mov ax,Default_ColorPlane
  154.     mov ah,0Fh
  155.     out dx,ax
  156.     pop dx
  157.     pop ax
  158.     ret
  159. end;
  160.  
  161. procedure Do_PixelAddr_EGAVGA; assembler;
  162. asm
  163. (* in ax=y, bx=x | *)
  164. (* CL=bits to shift BX = byte offset *)
  165. (* BX=Y*80+X/8 = Y*64+Y*16+X/8 = Y SHL 4 + Y SHL 6 + X SHR 3 *)
  166. (* CL=BL and 7 *)
  167.        mov ch,bl
  168.        and ch,7   (* mask *)
  169.        mov cl,3
  170.        shr bx,cl  (* bx=X/8 *)
  171.        inc cl
  172.        shl ax,cl  (* ax=Y*16 *)
  173.        add bx,ax  (* bx=Y*16+X/8 *)
  174.        shl ax,1
  175.        shl ax,1   (* ax=Y*64 *)
  176.        add bx,ax  (* bx=Y*64+Y*16+X/8 *)
  177.        mov cl,ch
  178. end;
  179.  
  180. procedure Do_Cursor_EGAVGA; assembler;
  181. asm
  182. (* Expect CH = start, CL = stop line (0..16), - in TvGraphCursor*)
  183. (* Expect X in DL, Y in DH - character co-ords - in TvGraphPos *)
  184.     push cx
  185.     push dx
  186.     push si
  187.     push es
  188.     xor [TvViziFlag],0FFh
  189.     mov cx,[TvGraphCursor]
  190.     mov dx,[TvGraphLoc]
  191.  
  192.     and cx,01F1Fh  (* ensure each is 0..31 only *)
  193.     cmp cl,ch
  194.     jb @SKIP
  195.     push cx
  196.     mov al,CharHeight
  197.     mul dh         (* ax:= Y*CharHeight *)
  198.  
  199.     xor dh,dh
  200.     mov si,dx      (* Si = X *)
  201.  
  202.     xchg ch,cl
  203.     xor ch,ch
  204.     add ax,cx      (* ax:= Y*CharHeight+StartLine *)
  205.     mov cx,80
  206.     mul cx         (* ax:= (Y*CharHeight+StartLine)*80 *)
  207.     add ax,dx      (* ax:= (Y*CharHeight+StartLine)*80 *)
  208.     add si,ax      (* si:= (Y*CharHeight+StartLine)*80 + X *)
  209.     pop cx
  210.     mov al,cl
  211.     xor ah,ah
  212.     sub al,ch      (* al:= (StopLine - StartLine) *)
  213.     inc al         (* al:= (StopLine - StartLine)+1 *)
  214.     mov cx,ax      (* use